package patrol.mobile.com.mobilepatrol.activity.security.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.adapter.BaseViewHolder;

import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.bean.PeopleInfoBean;

/**
 * Created by admin on 2018/9/9.
 */

public class EmergencyPeopleInfoLendAdapter extends BaseQuickAdapter<PeopleInfoBean.AnbkRentedHouseListBean> {

    private int currentItem = -1;

    public EmergencyPeopleInfoLendAdapter(Context context) {
        super(context);

    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.item_people_info_lend;
    }

    @Override
    protected void convert(final BaseViewHolder holder, PeopleInfoBean.AnbkRentedHouseListBean item) {

        holder.setTag(R.id.rl_arrow,holder.getAdapterPosition());
        if (currentItem == holder.getAdapterPosition()) {
            holder.setVisible(R.id.ll_coll, true);
            ImageView imageView =holder.getView(R.id.iv_arrowRota);
            imageView.setPivotX(imageView.getWidth()/2);
            imageView.setPivotY(imageView.getHeight()/2);//支点在图片中心
            imageView.setRotation(270);
        } else {
            holder.setVisible(R.id.ll_coll, false);
            ImageView imageView =holder.getView(R.id.iv_arrowRota);
            imageView.setPivotX(imageView.getWidth()/2);
            imageView.setPivotY(imageView.getHeight()/2);//支点在图片中心
            imageView.setRotation(0);
        }

        holder.setText(R.id.tv_num,(holder.getLayoutPosition()+1)+"");
        holder.setText(R.id.tv_rentName,item.getRentName());
        holder.setText(R.id.tv_comeDate,item.getComeDate());
        holder.setText(R.id.tv_timeLimit,item.getTimeLimit());
        holder.setText(R.id.tv_application,item.getApplication());
        holder.setText(R.id.tv_residencePermit,item.getResidencePermit().equals("1") ? "有"  : "无");
        //holder.setText(R.id.tv_mobpSex,item.getMobpSex().equals("1") ? "男"  : "女");
        holder.setText(R.id.tv_residence,item.getResidence());
        holder.setText(R.id.tv_company,item.getCompany());
        holder.setText(R.id.tv_rentMobile,item.getRentMobile());



        holder.setOnClickListener(R.id.rl_arrow, new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                int tag = (int) view.getTag();
                if (tag == currentItem) { //再次点击
                    currentItem = -1; //给 currentItem 一个无效值
                } else {
                    currentItem = tag;
                }
                //通知adapter数据改变需要重新加载
                notifyDataSetChanged(); //必须有的一步
            }
        });

    }
}
